@use "../_variables" as *;

.tool-details {
  margin: 10px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-op-dark-extremeweak);

  .tool-summary {
    padding: 10px 15px;
    cursor: pointer;
    user-select: none;
    font-weight: 500;

    &:hover {
      background: var(--bg-op-dark-extremeweak);
    }
  }

  .tool-content {
    padding: 15px;
    border-top: 1px solid;
    background: var(--bg-op-dark-ultraweak);
  }
}

.message.received {
  blockquote {
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 8px;
    border-left: 4px solid var(--border-pri-blue);
    background: var(--bg-op-dark-extremeweak);

    h3 {
      margin: 0 0 10px 0;
      font-size: 16px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    pre {
      margin: 10px 0 0 0;
    }
  }
}

.tool-panel {
  margin: 10px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-op-dark-extremeweak);

  summary {
    padding: 10px 15px;
    cursor: pointer;
    user-select: none;
    font-weight: 500;

    &:hover {
      background: var(--bg-op-dark-extremeweak);
    }
  }

  .tool-content {
    padding: 15px;
    border-top: 1px solid;
    max-height: 300px;
    overflow: auto;
    border-color: var(--border-weak);

    pre {
      margin: 0;
      white-space: pre-wrap;
      word-break: break-all;
    }
  }
}

.setup-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--bg-medium);
}

.setup-container {
  width: 100%;
  max-width: 600px;
  padding: 30px;
  border-radius: 12px;
  background: var(--bg-weak);
  box-shadow: 0 2px 10px var(--shadow-modal-light);

  h1 {
    margin: 0 0 10px;
    font-size: 24px;
  }

  .subtitle {
    margin-bottom: 30px;
    color: var(--text-weak);
  }

  .form-group {
    margin-bottom: 20px;

    label {
      display: block;
      margin-bottom: 8px;
      font-weight: 500;

      .required {
        color: var(--text-error);
        margin-left: 4px;
      }
    }

    .field-description,
    .field-model-description {
      font-size: 13px;
      margin-bottom: 8px;
      color: var(--text-weak);
    }
    .field-model-description {
      margin-bottom: -1rem;
    }

    input {
      width: 100%;
      padding: 8px 12px;
      border-radius: 6px;
      border: 1px solid var(--border);
      background: var(--bg-input);
      color: var(--text);
      transition: all 0.3s;

      &:focus {
        outline: none;
        border-color: var(--border-pri-blue);
        box-shadow: 0 0 0 2px var(--shadow-input);
      }

      &.error {
        border-color: var(--border-error);
      }
    }

    .error-message {
      color: var(--text-error);
      font-size: 14px;
      margin-top: 4px;
    }
  }

  .form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;

    button {
      flex: 1;
      padding: 12px;
      border: none;
      border-radius: 6px;
      font-size: 16px;
      cursor: pointer;
      transition: all 0.3s;
      display: flex;
      align-items: center;
      justify-content: center;

      &:disabled {
        opacity: 0.7;
        cursor: not-allowed;
      }

      .loading-spinner {
        width: 16px;
        height: 16px;
        border: 2px solid var(--border-inverted-op-mediumweak);
        border-radius: 50%;
        border-top-color: var(--border);
        animation: spin 0.8s linear infinite;
      }
    }

    .verify-btn {
      background: var(--bg-success);
      color: var(--text-light);
      
      &:hover:not(:disabled) {
        background: var(--bg-hover-success);
      }
      
      &:active:not(:disabled) {
        background: var(--bg-active-success);
      }
    }

    .submit-btn {
      background: var(--bg-pri-blue);
      color: var(--text-light);
      
      &:hover:not(:disabled) {
        background: var(--bg-hover-blue);
      }
      
      &:active:not(:disabled) {
        background: var(--bg-active-blue);
      }
    }
  }

  .provider-select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-select-weak);
    transition: all 0.3s;
    cursor: pointer;
    color: var(--text);

    &:focus {
      outline: none;
      border-color: var(--border-pri-blue);
      box-shadow: 0 0 0 2px var(--shadow-input);
    }
  }

  .back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 8px;
    margin-bottom: 16px;
    cursor: pointer;
    color: inherit;
    border-radius: 6px;

    &:hover {
      background: var(--bg-op-dark-extremeweak);
    }

    svg {
      fill: currentColor;
    }
  }
}

.tools-page {
  overflow: auto;

  .header-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;

    .edit-btn,
    .folder-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 16px;
      border: none;
      border-radius: 6px;
      font-size: 14px;
      cursor: pointer;
      transition: all 0.2s;

      svg {
        fill: currentColor;
      }
    }

    .edit-btn {
      background: var(--bg-pri-blue);
      color: var(--text-light);

      &:hover {
        background: var(--bg-hover-blue);
      }
    }

    .folder-btn {
      background: var(--bg-op-dark-extremeweak);

      &:hover {
        background: var(--bg-op-dark-ultraweak);
      }
    }
  }
}

.tools-container {
  width: 100%;
  max-width: 800px;

  h1 {
    margin: 0 0 16px;
    font-size: 28px;
  }

  .subtitle {
    color: var(--text-weak);
    margin-bottom: 32px;
  }
}

.tools-list {
  .tool-section {
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-medium);
    box-shadow: 0 2px 6px var(--shadow-modal-light);

    .tool-header {
      padding: 16px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      align-items: center;

      &:hover {
        background: var(--bg-op-dark-extremeweak);
      }

      .tool-header-content {
        display: flex;
        align-items: center;
        gap: 12px;

        img, svg {
          width: 24px;
          height: 24px;
          opacity: 0.7;
        }

        svg {
          fill: var(--stroke-op-dark-extremestrong);
        }

        .tool-name {
          font-weight: 500;
        }
      }

      .tool-toggle {
        font-size: 12px;
        transition: transform 0.3s;
      }
    }

    .tool-content {
      display: none;
      padding: 0 16px 16px;

      .tool-description {
        margin-bottom: 16px;
        color: var(--text-weak);
      }
    }

    &.expanded {
      .tool-toggle {
        transform: rotate(180deg);
      }

      .tool-content {
        display: block;
      }
    }

    .sub-tools {
      display: grid;
      gap: 12px;

      .sub-tool {
        padding: 12px;
        border-radius: 6px;
        background: var(--bg-op-dark-extremeweak);

        .sub-tool-name {
          font-weight: 500;
          margin-bottom: 4px;
        }

        .sub-tool-description {
          font-size: 14px;
          color: var(--text-weak);
        }
      }
    }
  }

  .error-message {
    padding: 16px;
    border-radius: 8px;
    background: #fff2f0;
    border: 1px solid #ffccc7;
    color: var(--text-error);
  }
}

.tool-switch-container {
  margin: 0 12px;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.sub-tool {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .sub-tool-content {
    flex: 1;
  }
}

.tool-header {
  .tool-header-content {
    flex: 1;
  }
}

.tools-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  position: relative;

  .header-actions {
    display: flex;
    gap: 12px;

    button {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 16px;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.2s;
      font-size: 14px;
      color: var(--text);

      svg {
        fill: currentColor;
      }

      [data-theme='dark'] {
        background: rgba(255, 255, 255, 0.1);

        &:hover {
          background: rgba(255, 255, 255, 0.15);
        }
      }
    }

    .add-btn {
      background: var(--bg-success);
      color: var(--text-light);

      &:hover {
        background: var(--bg-hover-success);
      }

      [data-theme='dark'] {
        background: rgba(82, 196, 26, 0.2);

        &:hover {
          background: rgba(82, 196, 26, 0.3);
        }
      }
    }

    .edit-btn {
      background: var(--bg-pri-blue);
      color: var(--text-light);

      &:hover {
        background: var(--bg-hover-blue);
      }

      [data-theme='dark'] {
        background: rgba(24, 144, 255, 0.2);

        &:hover {
          background: rgba(24, 144, 255, 0.3);
        }
      }
    }

    .folder-btn {
      background: var(--bg-op-dark-extremeweak);

      &:hover {
        background: var(--bg-op-dark-ultraweak);
      }
    }
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: $z-modal;
}

.modal-content {
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-weak);
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-modal);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-weak);

  h2 {
    margin: 0;
    font-size: 20px;
  }

  .close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: inherit;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
  }
}

.config-form {
  padding: 24px;

  .form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;

    button {
      padding: 8px 16px;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.3s;
    }

    .cancel-btn {
      background: none;
      border: 1px solid var(--border);
      color: var(--text);

      &:hover {
        border-color: var(--border-hover-blue);
        color: var(--text-hover-blue);
      }
    }

    .submit-btn {
      background: var(--bg-pri-blue);
      color: var(--text-light);

      &:hover {
        background: var(--bg-hover-blue);
      }
    }
  }

  .cm-scroller {
    @include scrollbar;
  }
}

.config-textarea {
  width: 100%;
  min-height: 300px;
  font-family: monospace;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);

  &:focus {
    outline: none;
    border-color: var(--border-pri-blue);
    box-shadow: 0 0 0 2px var(--shadow-input);
  }
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-inverted-op-mediumweak);
  border-radius: 50%;
  border-top-color: var(--border);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.form-actions {
  button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
  }
}

.global-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-op-dark-ultraweak);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;

  .loading-spinner {
    width: 40px;
    height: 40px;
    border-width: 4px;
  }
}
